﻿using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;

namespace Messhall.Framework.SwaggerGens
{
    public static class SwaggerGenOptionsExtensions
    {
        public static void IncludeXmlComments(this SwaggerGenOptions swaggerGenOptions, string location)
        {
            // 解决相同类名会报错的问题
            swaggerGenOptions.CustomSchemaIds(type => type.FullName);
            foreach (var item in Directory.GetFiles(Path.GetDirectoryName(location), "*.xml"))
            {
                swaggerGenOptions.IncludeXmlComments(item, true);
            }
        }
    }
}
